package com.seesman.application.maintenance.common.gui.utilities;

import java.awt.Color;
import java.awt.Container;

import javax.swing.JFrame;
import javax.swing.UIManager;

/**
 * Utility class that simplify using windows in Swing.
 * 
 * @author jhayne_mjvb
 *
 */
public class WindowUtilities {

	public static void setNativeLookAndFeel() {
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
	    } catch(Exception e) {
	    	System.out.println("Error setting native LAF: " + e);
	    }
	}
	
	public static void setJavaLookAndFeel() {
		try {
			UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
	    } catch(Exception e) {
	    	System.out.println("Error setting Java LAF: " + e);
	    }
	}
	
	/**
	 * A simplified way to see a JPanel or other Container.
	 * 
	 * @param content
	 * @param width
	 * @param height
	 * @param title
	 * @param bgColor
	 * @return
	 */
	public static JFrame openInJFrame(Container content,
							            int width,
							            int height,
							            String title,
							            Color bgColor) {
		JFrame frame = new JFrame(title);
		frame.setBackground(bgColor);
		content.setBackground(bgColor);
		frame.setSize(width, height);
		frame.setContentPane(content);
		frame.addWindowListener(new ExitListener());
		frame.setVisible(true);
		return(frame);
	}

	/**
	 * Uses Color.white as the background color
	 * 
	 * @param content
	 * @param width
	 * @param height
	 * @param title
	 * @return
	 */
	public static JFrame openInJFrame(Container content,
							            int width,
							            int height,
							            String title) {
		return(openInJFrame(content, width, height, title, Color.gray));
	}
	
	/**
	 * Uses Color.white as the background color, and the name of the 
	 * Container's class as the JFrame title
	 * 
	 * @param content - Container
	 * @param width
	 * @param height
	 * @return
	 */
	public static JFrame openInJFrame(Container content,
							            int width,
							            int height) {
		return(openInJFrame(content, width, height, content.getClass().getName(), Color.gray));
	}
	
}
